package AI.screens
{
	import com.cheezeworld.AI.AISettings;
	import com.cheezeworld.AI.Behaviors.*;
	import com.cheezeworld.entity.*;
	import com.cheezeworld.math.MathUtils;
	import com.cheezeworld.rendering.MovingEntityRenderer;
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.screens.Root;
	import com.cheezeworld.utils.Input;

	public class ObstacleAvoidanceDemo extends AIDemoScreen
	{
		public function ObstacleAvoidanceDemo(a_parentScreen:IScreenItem=null)
		{
			super(a_parentScreen);
			
			screenLabel = "Obstacle Avoidance";
			
			var i:int;
			var rx:Number;
			var ry:Number;
			var rr:Number;
			
			// Create some obstacles
			var obstacles:Array = [];
			var ob:Entity;
			for( i=0; i<3; i++ )
			{
				ob = _factory.getEntity( "Obstacle", _gameworld );
				rr = MathUtils.rand( 25, 35 );
				rx = MathUtils.rand( rr, Root.WIDTH - rr );
				ry = MathUtils.rand( rr, Root.HEIGHT - rr );
				ob.radius = rr;
				ob.newPos.Set( rx, ry );
				obstacles.push( ob );
			}
			
			// Create some boids
			
			var boid:Boid;
			for( i = 0; i < 6; i++ )
			{
				boid = _factory.getEntity( "Boid1", _gameworld ) as Boid;
				boid.steering.addBehavior( new Wander() );
				boid.steering.addBehavior( new ObstacleAvoidance( obstacles ) );
			}
			
			boid = _factory.getEntity( "Boid1", _gameworld ) as Boid;
			boid.steering.addBehavior( new Arrive( Input.instance.worldMousePos, AISettings.arriveFast ) );
			boid.steering.addBehavior( new ObstacleAvoidance( obstacles ) );
			
			_factory.getRenderer( boid, MovingEntityRenderer );
			
		}	
		
	}
}